package com.lemon.smartsafetynew.ui.fragment.record;

import android.os.Bundle;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.ui.fragment.base.BasePullToRefreshFragment;
import com.lemon.smartsafety.utils.app.UIHelper;
import com.lemon.smartsafetynew.entity.air.AirItmeVo;
import com.lemon.smartsafetynew.entity.electrical.ElectricalCompanyVo;
import com.lemon.smartsafetynew.entity.me.MeCompanyVo;
import com.lemon.smartsafetynew.net.services.RecordServices;
import com.lemon.smartsafetynew.ui.activity.air.AirListActivity;
import com.lemon.smartsafetynew.ui.adapter.record.AirAdapter;
import com.lemon.smartsafetynew.util.constants.KeyConstants;

import java.util.List;

import kale.adapter.LemonRcvAdapter;

/**
 * 可燃/有毒气体
 * Created by Andrew on 2018/3/19.
 */

public class AirFragment extends BasePullToRefreshFragment<AirItmeVo, List<AirItmeVo>>
        implements RecyclerTClickListener<AirItmeVo> {

    private static MeCompanyVo companyVo;

    @Override
    protected void getBaseArguments() {
        super.getBaseArguments();

        Bundle bundle = getArguments();
        if (bundle != null) {
            if (bundle.containsKey(KeyConstants.KEY_COMPANY_VO)) {
                companyVo = (MeCompanyVo) bundle.getSerializable(KeyConstants.KEY_COMPANY_VO);
            }
        }
    }

    public static AirFragment newInstance(MeCompanyVo companyVo) {

        Bundle args = new Bundle();
        args.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);

        AirFragment fragment = new AirFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onPullRefresh() {
        LemonRequestParams params = new LemonRequestParams("");
        params.put("company_id", companyVo.getCompany_id());
        params.put("pageNum", currentPage);
        params.put("pageSize", pageSize);
        RecordServices.init().getAirInfoList(RefreshType.REFRESH, params);
    }

    @Override
    public void onLoadMore() {
        LemonRequestParams params = new LemonRequestParams("");
        params.put("company_id", companyVo.getCompany_id());
        params.put("pageNum", currentPage);
        params.put("pageSize", pageSize);
        RecordServices.init().getAirInfoList(RefreshType.LOAD_MORE, params);
    }

    @Override
    public boolean goRefreshOnCreate() {
        return true;
    }

    @Override
    public LemonRcvAdapter<AirItmeVo> getLemonAdapter() {
        return new AirAdapter(mDataList, this);
    }

    @Override
    public String getHttpTag() {
        return KeyConstants.URL_COMPANY_INFO_AIR_LIST;
    }

    @Override
    public void onItemClick(AirItmeVo data, int position) {

        ElectricalCompanyVo electricalCompanyVo = new ElectricalCompanyVo();
        electricalCompanyVo.setCompanyId(companyVo.getCompany_id());

        Bundle bundle = new Bundle();
        bundle.putSerializable(KeyConstants.KEY_ELECTRICAL_COMPANY_INFO, electricalCompanyVo);
        UIHelper.showActivity(getmContext(), bundle, AirListActivity.class);
    }
}
